package com.jiming.webrpc.utiles;

import com.jiming.webrpc.WebRpcException;

public class TokenUtile {
	
	public static void checkToken(String token) {
		if(token == null || token.length() < 16) {
			throw new WebRpcException("Token size must gt 16.");
		}
		
		if(token.matches(".*[\\W]+.*")) {
			//非法字符
			throw new WebRpcException("Token inclus character.");
		}
		
		if(!token.matches(".*[a-z]+.*")) {
			//没有包含小写字母
			throw new WebRpcException("Token must inclus lower case letters.");
		}
		
		if(!token.matches(".*[A-Z]+.*")) {
			//没有包含大写字母
			throw new WebRpcException("Token must inclus upper case letters.");
		}
		
		if(!token.matches(".*[0-9]+.*")) {
			//没有包含数字
			throw new WebRpcException("Token must inclus numbers.");
		}
	}
	
}
